@echo off
set /p installpath=Please enter the drive letter (default: C):
if "%installpath%"=="" (
    set "installpath=C:\ProgramData\miniconda"
) else (
    set "installpath=%installpath%:\ProgramData\miniconda"
)
echo.
echo Installing to "%installpath%"
setx MINICONDAPATH "%installpath%" /M
setx MINICONDAPATH "%installpath%"
set "MINICONDAPATH=%installpath%"
if not exist "%installpath%\python.exe" (
    echo Installing Miniconda...
    curl -L https://repo.anaconda.com/miniconda/Miniconda3-py311_24.11.1-0-Windows-x86_64.exe -o miniconda.exe
    start /wait "" .\miniconda.exe /S /AddToPath=0 /NoRegistry=1 /Shortcuts=0 /D=%MINICONDAPATH%
    del miniconda.exe
    set "PATH=%PATH%;%MINICONDAPATH%\Scripts;%MINICONDAPATH%"
    "%MINICONDAPATH%\python.exe" -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    "%MINICONDAPATH%\python.exe" -m pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
    "%MINICONDAPATH%\python.exe" -m pip install --upgrade pip
)
if not exist "%installpath%\ffmpeg.exe" (
    echo Installing ffmpeg...
    curl -L https://ghproxy.net/https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n7.1-latest-win64-gpl-7.1.zip -o ffmpeg.zip
    tar -xzvf ffmpeg.zip -C "%MINICONDAPATH%"
    for /d %%F in ("%MINICONDAPATH%\ffmpeg*") do (
        ren "%%F" "ffmpeg"
    )
    move "%MINICONDAPATH%\ffmpeg\bin\*.*" "%MINICONDAPATH%\"
    rmdir /s /q "%MINICONDAPATH%\ffmpeg"
    del ffmpeg.zip
)
pause